"use strict";
cc._RF.push(module, '8b6ebvuMgtC7KdzzlA5AitY', 'AttributeDetailsView');
// scripts/AttributeDetailsView.js

"use strict";

var t = require;
var e = module;
var o = exports;

var _i,
    n = void 0 && (void 0).__extends || (_i = function i(t, e) {
  return (_i = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _i(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    a = void 0 && (void 0).__decorate || function (t, e, o, i) {
  var n,
      a = arguments.length,
      r = a < 3 ? e : null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);else for (var s = t.length - 1; s >= 0; s--) {
    (n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
  }
  return a > 3 && r && Object.defineProperty(e, o, r), r;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});

var r = t("AssemblyItem"),
    s = t("GlobalUserData"),
    l = t("SellHintView"),
    c = t("BroadCastMessage"),
    d = t("HallConstant"),
    h = t("Hint"),
    p = t("Util"),
    u = t("HallGoldSupply"),
    f = t("StorageManager"),
    m = t("Global"),
    _ = t("BaseStorage"),
    y = t("CarConstant"),
    g = t("ChampionManager"),
    v = cc._decorator,
    C = v.ccclass,
    b = v.property,
    w = function (t) {
  function e() {
    var e = null !== t && t.apply(this, arguments) || this;
    return e.pfb_assemblyItem = null, e.pfb_sellHint = null, e.pfb_getGold = null, e.lab_name = null, e.lab_level = null, e.lab_type = null, e.lab_rarity = null, e.lab_details = null, e.lab_ownGold = null, e.lab_upgradeGold = null, e.lab_ownDiamond = null, e.lab_upgradeDiamond = null, e.node_upgradeTip = null, e.node_hp = null, e.node_elec = null, e.node_damage = null, e.node_item = null, e.node_BtnNext = null, e.node_BtnNext_no = null, e.node_BtnPre = null, e.node_BtnPre_no = null, e.node_BtnSell = null, e.node_BtnUpGrade = null, e.node_BtnVideo = null, e.ps_upGrade = null, e.node_guide = null, e.spr_tagIcon = null, e.frame_tagIconArr = new Array(), e.label_Info = null, e.label_Info_Value = null, e.label_power = null, e.assemblyItem = null, e._sellHint = null, e.nUpGradeGold = 0, e.nUpGradeDiamond = 0, e._itemData = null, e.videoIcon = null, e.TTVideoIcon = null, e._hallControl = null, e._attributeView = null, e.allItemData = [], e.nCurShowIndex = 0, e;
  }

  return n(e, t), e.prototype.start = function () {
    this.TTVideoIcon.active = !1, p.Util.is_tt() && s["default"].bAuditMode && (this.videoIcon.active = !1, this.TTVideoIcon.active = !0), f.StorageManager.setDailyTaskStorageKey(m.BaseStorageKey.UpgradeNumber);
  }, e.prototype.init = function (t, e) {
    this._hallControl = t, this._attributeView = e;
  }, e.prototype.onEnable = function () {
    this.onSetOwnGold(), p.Util.is_VIVO() && p.Util.showBanner(), p.Util.is_wx() && (p.Util.showBanner(), p.Util.show_VerticalCustomAd(!1), p.Util.show_VerticalCustomAd(!0), p.Util.hideSingleCustomAd()), p.Util.is_tt() && s["default"].bAuditMode;
  }, e.prototype.onSetOwnGold = function () {
    this.lab_ownGold.string = p.Util.transformGoldStr(s["default"].nGlod), this.lab_ownDiamond.string = p.Util.transformGoldStr(s["default"].nDiamond);
  }, e.prototype.onSetUpGradeGold = function (t) {
    t = t || 1, this.nUpGradeGold = Math.floor(20 * Math.pow(t, 3) + 60), this.nUpGradeDiamond = Math.floor(Math.pow(t, 3) / 50 + 5), this.nUpGradeGold -= Math.floor(this.nUpGradeGold * g["default"].Ins.getGradeBuff(s["default"].nTrophy, null).upgrade), this.nUpGradeDiamond -= Math.floor(this.nUpGradeDiamond * g["default"].Ins.getGradeBuff(s["default"].nTrophy, null).upgrade), this.lab_upgradeGold.string = p.Util.transformGoldStr(this.nUpGradeGold), this.lab_upgradeDiamond.string = p.Util.transformGoldStr(this.nUpGradeDiamond), t < y.Item_Level_Max ? (s["default"].nGlod >= this.nUpGradeGold ? (this.node_upgradeTip.active = !0, this.lab_ownGold.node.color = cc.color(255, 255, 255)) : (this.node_upgradeTip.active = !1, this.lab_ownGold.node.color = cc.color(193, 37, 37)), s["default"].nDiamond >= this.nUpGradeDiamond ? this.lab_ownDiamond.node.color = cc.color(255, 255, 255) : (this.node_upgradeTip.active = !1, this.lab_ownDiamond.node.color = cc.color(193, 37, 37))) : (this.node_upgradeTip.active = !1, this.lab_ownGold.node.color = cc.color(255, 255, 255), this.lab_ownDiamond.node.color = cc.color(255, 255, 255));
  }, e.prototype.updateView = function (t) {
    this.node.active = !0, this._itemData = t, this.label_power.string = "战力：" + p.Util.getOwnItemPower(t), this.createItem(t), this.setLabelString(t), this.updateAttribute(t), this.resetView(t);
  }, e.prototype.resetView = function (t) {
    var e = this;
    this.isitemEquip(t.type, t.uid) ? (this.node_BtnNext.active = !1, this.node_BtnPre.active = !1, this.node_BtnNext_no.active = !1, this.node_BtnPre_no.active = !1, this.node_BtnSell.active = !1, this.node_BtnUpGrade.x = 0, this.node_BtnVideo.x = 0, p.Util.is_tt() && s["default"].bAuditMode) : (this.node_BtnUpGrade.x = 136, this.node_BtnVideo.x = 136, this.node_BtnNext.active = !0, this.node_BtnPre.active = !0, this.node_BtnNext_no.active = !1, this.node_BtnPre_no.active = !1, this.node_BtnSell.active = !0, this.getAllAssemblyData(t.uid), 0 == this.nCurShowIndex && (this.node_BtnPre.active = !1, this.node_BtnPre_no.active = !0), this.nCurShowIndex == this.allItemData.length - 1 && (this.node_BtnNext.active = !1, this.node_BtnNext_no.active = !0)), this._attributeView._hallControl._assemblyView.isGuide && this.scheduleOnce(function () {
      e._attributeView._hallControl._assemblyView.onGuideUpgrade(e.node_BtnUpGrade);
    }, .5);
  }, e.prototype.onShowGuide = function () {}, e.prototype.onGuideHandle = function () {}, e.prototype.onBtnClose = function () {
    this.playAudio(d.Audio_ID.btn_click), this.node.active = !1;
  }, e.prototype.onDisable = function () {
    p.Util.hideBanner(), p.Util.is_wx() && (p.Util.hide_VerticalCustomAd(!1), p.Util.hide_VerticalCustomAd(!0), p.Util.showSingleCustomAd(cc.v2(150, -60)));
  }, e.prototype.onShowBtnVideo = function () {
    this.node_BtnUpGrade.active = !0, this.node_BtnVideo.active = !1, 0 == s["default"].bAuditMode && s["default"].clickUpgradeTimes >= 0 && s["default"].upgradeVideoList[s["default"].clickUpgradeTimes] && (this.node_BtnUpGrade.active = !1, this.node_BtnVideo.active = !0);
  }, e.prototype.onBtnUpgrade = function () {
    if (this.playAudio(d.Audio_ID.btn_click), this._attributeView._hallControl.hideGuide(), s["default"].saveUpgradeState(), s["default"].nGlod >= this.nUpGradeGold) {
      if (s["default"].nDiamond >= this.nUpGradeDiamond) {
        if (this.onUpgradeData()) {
          s["default"].clickUpgradeTimes++, s["default"].clickUpgradeTimes >= s["default"].upgradeVideoList.length && (s["default"].clickUpgradeTimes = 0);
          var t = _.BaseStorage.getInt(m.BaseStorageKey.UpgradeNumber, 0) + 1;
          _.BaseStorage.setInt(m.BaseStorageKey.UpgradeNumber, t), this.playAudio(d.Audio_ID.item_upgrade), s["default"].saveGoldData(!1, this.nUpGradeGold), s["default"].saveDiamondData(!1, this.nUpGradeDiamond), this.onSetOwnGold(), this.onSetUpGradeGold(this._itemData.level), this.updateAttribute(this._itemData), this._attributeView.updateAttribute(this._itemData), this._hallControl.onSetOwnGold(), this._hallControl.onSetOwnDiamond(), this._hallControl._assemblyView.updateAttributeTotal(), this.ps_upGrade.resetSystem();
        }
      } else p.Util.is_qg() || (h["default"].show("钻石不足！"), this.onGetDiamond());
    } else p.Util.is_qg() || (h["default"].show("金币不足！"), this.onGetGold());
  }, e.prototype.onBtnUpgradeVideo = function () {
    var t = this;
    this.playAudio(d.Audio_ID.btn_click), p.Util.showRewardVideo(function () {
      if (t.onUpgradeData()) {
        s["default"].saveUpgradeState(), s["default"].clickUpgradeTimes++, s["default"].clickUpgradeTimes >= s["default"].upgradeVideoList.length && (s["default"].clickUpgradeTimes = 0);
        var e = _.BaseStorage.getInt(m.BaseStorageKey.UpgradeNumber, 0) + 1;
        _.BaseStorage.setInt(m.BaseStorageKey.UpgradeNumber, e), t.playAudio(d.Audio_ID.item_upgrade), t.onSetOwnGold(), t.onSetUpGradeGold(t._itemData.level), t.updateAttribute(t._itemData), t._attributeView.updateAttribute(t._itemData), t._hallControl.onSetOwnGold(), t._hallControl.onSetOwnDiamond(), t._hallControl._assemblyView.updateAttributeTotal(), t.ps_upGrade.resetSystem();
      }
    });
  }, e.prototype.onUpgradeData = function () {
    if (this._itemData && null != this._itemData.video && this._itemData.video) h["default"].show("此组件无法升级");else {
      if (!(this._itemData.level >= y.Item_Level_Max)) {
        switch (this._itemData.level = this._itemData.level + 1, this._itemData.type) {
          case y.Basics_Items_Type.body:
            s["default"].upGradeBodyData(this._itemData);
            break;

          case y.Basics_Items_Type.wheel:
            s["default"].upGradeWheelData(this._itemData);
            break;

          case y.Basics_Items_Type.weapon:
            s["default"].upGradeWeaponData(this._itemData);
            break;

          case y.Basics_Items_Type.tools:
            s["default"].upGradeToolsData(this._itemData);
            break;

          default:
            return this._itemData.level = this._itemData.level - 1, h["default"].show("升级失败！请稍后重试"), !1;
        }

        return h["default"].show("升级成功！"), !0;
      }

      h["default"].show("已升级到最大等级！");
    }
  }, e.prototype.onBtnSell = function () {
    if (this._itemData && null != this._itemData.video && this._itemData.video) h["default"].show("此组件无法出售");else {
      if (this.playAudio(d.Audio_ID.btn_click), !this._sellHint) {
        var t = cc.instantiate(this.pfb_sellHint);
        this._hallControl.node.addChild(t, 60), this._sellHint = t.getComponent(l["default"]), this._sellHint.init(this);
      }

      this._sellHint.updateView(this.allItemData[this.nCurShowIndex]);
    }
  }, e.prototype.onSellSucceed = function () {
    this.onSetOwnGold(), this._hallControl.onSetOwnGold(), this._hallControl._assemblyView.updateScrolView();
    var t = this._hallControl._assemblyView.arrAssemblyData;
    t.length <= 0 ? this.onBtnClose() : (this._attributeView.updateView(t[0]), this.updateView(t[0]));
  }, e.prototype.onGetGold = function () {
    var t = this,
        e = cc.instantiate(this.pfb_getGold);
    this.node.addChild(e), e.getComponent(u["default"]).initView(u.Supply_Type.Gold, this._hallControl, function () {
      t.onSetOwnGold(), t._hallControl.onSetOwnGold(), t.onSetUpGradeGold(t._itemData.level);
    });
  }, e.prototype.onGetDiamond = function () {
    var t = this,
        e = cc.instantiate(this.pfb_getGold);
    this.node.addChild(e), e.getComponent(u["default"]).initView(u.Supply_Type.Diamond, this._hallControl, function () {
      t.onSetOwnGold(), t._hallControl.onSetOwnDiamond(), t.onSetUpGradeGold(t._itemData.level);
    });
  }, e.prototype.getHallGoldPos = function () {
    return this._hallControl.getGoldWorldPos();
  }, e.prototype.onBtnNext = function () {
    this.playAudio(d.Audio_ID.btn_click), this.nCurShowIndex++, this.nCurShowIndex >= this.allItemData.length ? this.nCurShowIndex = this.allItemData.length - 1 : (this.node_BtnNext.active = !0, this.node_BtnPre.active = !0, this.node_BtnNext_no.active = !1, this.node_BtnPre_no.active = !1, 0 == this.nCurShowIndex && (this.node_BtnPre.active = !1, this.node_BtnPre_no.active = !0), this.nCurShowIndex == this.allItemData.length - 1 && (this.node_BtnNext.active = !1, this.node_BtnNext_no.active = !0), this.updateView(this.allItemData[this.nCurShowIndex]));
  }, e.prototype.onBtnPre = function () {
    this.playAudio(d.Audio_ID.btn_click), this.nCurShowIndex--, this.nCurShowIndex < 0 ? this.nCurShowIndex = 0 : (this.node_BtnNext.active = !0, this.node_BtnPre.active = !0, this.node_BtnNext_no.active = !1, this.node_BtnPre_no.active = !1, 0 == this.nCurShowIndex && (this.node_BtnPre.active = !1, this.node_BtnPre_no.active = !0), this.nCurShowIndex == this.allItemData.length - 1 && (this.node_BtnNext.active = !1, this.node_BtnNext_no.active = !0), this.updateView(this.allItemData[this.nCurShowIndex]));
  }, e.prototype.getAllAssemblyData = function (t) {
    this.allItemData = this._hallControl._assemblyView.arrAssemblyData;

    for (var e = 0; e < this.allItemData.length; e++) {
      if (this.allItemData[e].uid == t) return void (this.nCurShowIndex = e);
    }
  }, e.prototype.updateAttribute = function (t) {
    this.lab_level.string = (t.level || "1") + "级", this.onSetUpGradeGold(t.level);
    var e = [cc.v3(196, 159), cc.v3(196, 108), cc.v3(196, 159)],
        o = 0;

    if (t.hp) {
      this.node_hp.active = !0, this.node_hp.position = e[o], o++;
      var i = p.Util.transformHpNum(t.hp, t.level),
          n = p.Util.transformHpNum(t.hp, t.level + 1),
          a = n - i <= 0 ? 1 : n - i;
      this.node_hp.getChildByName("label").getComponent(cc.Label).string = "" + i, this.node_hp.getChildByName("label_add").getComponent(cc.Label).string = ":" + a;
    } else this.node_hp.active = !1;

    if (t.damage) {
      this.node_damage.active = !0, this.node_damage.position = e[o], o++;
      var r = p.Util.transformDamageNum(t.damage, t.level),
          l = p.Util.transformDamageNum(t.damage, t.level + 1);
      a = l - r <= 0 ? 1 : l - r, this.node_damage.getChildByName("label").getComponent(cc.Label).string = "" + r, this.node_damage.getChildByName("label_add").getComponent(cc.Label).string = ":" + a;
    } else this.node_damage.active = !1;

    t.elec ? (this.node_elec.active = !0, this.node_elec.position = e[o], o++, this.node_elec.getChildByName("label").getComponent(cc.Label).string = "" + t.elec) : this.node_elec.active = !1, this.label_power.string = "战力：" + p.Util.getOwnItemPower(t), this.node_BtnVideo.active = !1, this.node_BtnUpGrade.active = !0, s["default"].nGlod < this.nUpGradeGold || s["default"].nDiamond < this.nUpGradeDiamond ? (this.node_BtnUpGrade.active = !1, this.node_BtnVideo.active = !0, p.Util.is_tt() && s["default"].bAuditMode) : this.onShowBtnVideo();
  }, e.prototype.setBuffInfo = function (t) {
    if (t) {
      switch (this.spr_tagIcon.spriteFrame = this.frame_tagIconArr[Number(t.buffType)], this.label_Info.node.color = cc.color(159, 0, 129), this.label_Info_Value.node.color = this.label_Info.node.color, t.type) {
        case y.Basics_Items_Type.body:
          this.label_Info.string = "装备的" + y.getBodyData(t.id).name;
          break;

        case y.Basics_Items_Type.wheel:
          this.label_Info.string = "装备的" + y.getWheelData(t.id).name;
          break;

        case y.Basics_Items_Type.weapon:
          this.label_Info.string = "装备的" + y.getWeaponData(t.id).name;
          break;

        case y.Basics_Items_Type.tools:
          this.label_Info.string = "装备的" + y.getToolsData(t.id).name;
      }

      this.label_Info_Value.string = "+" + Math.round(100 * (t.number - 1)) + "%";
    } else this.label_Info.node.parent.active = !1;
  }, e.prototype.setLabelString = function (t) {
    switch (this.lab_rarity.node.color = cc.color(255, 255, 255), t.type) {
      case y.Basics_Items_Type.body:
        var e = y.GetCarBodyData(t.id);
        this.lab_type.string = "车身", this.lab_name.string = "" + e.name, this.lab_rarity.string = "普通", this.setRareType(this.lab_rarity, t.quality || m.Quality.common), this.lab_details.string = e.description;
        break;

      case y.Basics_Items_Type.wheel:
        var o = y.GetCarWheelData(t.id);
        this.lab_type.string = "车轮", this.lab_name.string = "" + o.name, this.lab_rarity.string = "普通", this.lab_details.string = o.description;
        break;

      case y.Basics_Items_Type.weapon:
        var i = y.GetCarWeaponData(t.id);
        this.lab_type.string = "武器", this.lab_name.string = "" + i.name, this.lab_rarity.string = "普通", this.setRareType(this.lab_rarity, t.quality || m.Quality.common), this.lab_details.string = i.description;
        break;

      case y.Basics_Items_Type.tools:
        var n = y.GetCarToolsData(t.id);
        this.lab_type.string = "辅助武器", this.lab_name.string = "" + n.name, this.lab_rarity.string = "普通", this.lab_details.string = n.description;
    }
  }, e.prototype.setRareType = function (t, e) {
    switch (e) {
      case m.Quality.common:
        t.string = "普通", t.node.color = cc.color(255, 255, 255);
        break;

      case m.Quality.epic:
        t.string = "史诗", t.node.color = cc.color(159, 0, 129);
        break;

      case m.Quality.Legendary:
        t.string = "传说", t.node.color = cc.color(255, 80, 4);
        break;

      default:
        t.string = "普通", t.node.color = cc.color(255, 255, 255);
    }
  }, e.prototype.createItem = function (t) {
    if (!this.assemblyItem) {
      var e = cc.instantiate(this.pfb_assemblyItem);
      e.position = cc.v3(0, 0, 0), this.node_item.addChild(e), this.assemblyItem = e;
    }

    switch (this.assemblyItem.getComponent(r.AssemblyItem).updateItem(null, !0, 0, t, !1, r.Assembly_Type.Attribute), this.label_Info.node.parent.active = !0, t.type) {
      case y.Basics_Items_Type.body:
        t.quality == m.Quality.common ? this.label_Info.node.parent.active = !1 : this.setBuffInfo(t.buff);
        break;

      default:
        this.label_Info.node.parent.active = !1;
    }
  }, e.prototype.isitemEquip = function (t, e) {
    switch (t) {
      case y.Basics_Items_Type.body:
        return this.isOwnUidEquipBody(e);

      case y.Basics_Items_Type.wheel:
        return this.isOwnUidEquipWheel(e);

      case y.Basics_Items_Type.weapon:
        return this.isOwnUidEquipWeapon(e);

      case y.Basics_Items_Type.tools:
        return this.isOwnUidEquipUseTools(e);
    }

    return !1;
  }, e.prototype.isOwnUidEquipBody = function (t) {
    for (var e = 0; e < s["default"].curEquipBody.length; e++) {
      if (t == s["default"].curEquipBody[e]) return !0;
    }

    return !1;
  }, e.prototype.isOwnUidEquipWheel = function (t) {
    for (var e = 0; e < s["default"].curEquipWheel.length; e++) {
      for (var o = 0; o < s["default"].curEquipWheel[e].length; o++) {
        if (t == s["default"].curEquipWheel[e][o]) return !0;
      }
    }

    return !1;
  }, e.prototype.isOwnUidEquipWeapon = function (t) {
    for (var e = 0; e < s["default"].curEquipWeapon.length; e++) {
      for (var o = 0; o < s["default"].curEquipWeapon[e].length; o++) {
        if (t == s["default"].curEquipWeapon[e][o]) return !0;
      }
    }

    return !1;
  }, e.prototype.isOwnUidEquipUseTools = function (t) {
    for (var e = 0; e < s["default"].curEquipTools.length; e++) {
      for (var o = 0; o < s["default"].curEquipTools[e].length; o++) {
        if (t == s["default"].curEquipTools[e][o]) return !0;
      }
    }

    return !1;
  }, e.prototype.playAudio = function (t) {
    this._hallControl ? this._hallControl.playAudio(t) : c["default"].getInstance().SendMessage(d.Broadcast_Func.Audio, t);
  }, a([b(cc.Prefab)], e.prototype, "pfb_assemblyItem", void 0), a([b(cc.Prefab)], e.prototype, "pfb_sellHint", void 0), a([b(cc.Prefab)], e.prototype, "pfb_getGold", void 0), a([b(cc.Label)], e.prototype, "lab_name", void 0), a([b(cc.Label)], e.prototype, "lab_level", void 0), a([b(cc.Label)], e.prototype, "lab_type", void 0), a([b(cc.Label)], e.prototype, "lab_rarity", void 0), a([b(cc.Label)], e.prototype, "lab_details", void 0), a([b(cc.Label)], e.prototype, "lab_ownGold", void 0), a([b(cc.Label)], e.prototype, "lab_upgradeGold", void 0), a([b(cc.Label)], e.prototype, "lab_ownDiamond", void 0), a([b(cc.Label)], e.prototype, "lab_upgradeDiamond", void 0), a([b(cc.Node)], e.prototype, "node_upgradeTip", void 0), a([b(cc.Node)], e.prototype, "node_hp", void 0), a([b(cc.Node)], e.prototype, "node_elec", void 0), a([b(cc.Node)], e.prototype, "node_damage", void 0), a([b(cc.Node)], e.prototype, "node_item", void 0), a([b(cc.Node)], e.prototype, "node_BtnNext", void 0), a([b(cc.Node)], e.prototype, "node_BtnNext_no", void 0), a([b(cc.Node)], e.prototype, "node_BtnPre", void 0), a([b(cc.Node)], e.prototype, "node_BtnPre_no", void 0), a([b(cc.Node)], e.prototype, "node_BtnSell", void 0), a([b(cc.Node)], e.prototype, "node_BtnUpGrade", void 0), a([b(cc.Node)], e.prototype, "node_BtnVideo", void 0), a([b(cc.ParticleSystem)], e.prototype, "ps_upGrade", void 0), a([b(cc.Node)], e.prototype, "node_guide", void 0), a([b(cc.Sprite)], e.prototype, "spr_tagIcon", void 0), a([b([cc.SpriteFrame])], e.prototype, "frame_tagIconArr", void 0), a([b(cc.Label)], e.prototype, "label_Info", void 0), a([b(cc.Label)], e.prototype, "label_Info_Value", void 0), a([b(cc.Label)], e.prototype, "label_power", void 0), a([b(cc.Node)], e.prototype, "videoIcon", void 0), a([b(cc.Node)], e.prototype, "TTVideoIcon", void 0), a([C], e);
}(cc.Component);

o["default"] = w;

cc._RF.pop();